import { ElMessage } from 'element-plus'
import { ListPage } from "custom/index";
import { getShopDistributeRulePage, removeScriptManagePage } from './api'
import { addDialog, editDialog } from './dialog'
import { copyToClipboard } from '@/utils/common'
import { setDefault, customerInspection } from './action'

export async function copyAction({ props }) {
  const row = props.row || {}
  copyToClipboard(row.content || '')
  ElMessage.success('操作成功') 
}

const page = new ListPage('StoreAllocationRules');

page
  .api(getShopDistributeRulePage)
  .useSearch()
    .addInputItem('keyword', '规则名称')
    .end()
  .useTable()
    .useIndexColumn().end()
    .useColumn('ruleName').label('规则名称').minWidth(140).end()
    .useColumn('createTime').label('最后变更时间').minWidth(200).sortable().end()
    .useColumn('defaultFlag').label('默认启用').formatter(row => row.defaultFlag ? '是' : '否').minWidth(140).end()
    .useColumn('shopName').label('所属店铺').minWidth(140).sortable().end()
    .useColumn('createUserName').label('创建人').minWidth(140).sortable().end()
    .end()
  .usePagination()
    .end()
  .useAuthButton()
    .useItem('add').primary().content('新增').addRow(addDialog).end()
    .end()
  .useAuthColumn({ width: 100, label: '客服检测' })
    .useItem('detection').content('客服检测').action(customerInspection).end()
    .end()
  .useAuthColumn({ width: 180 })
    .useItem('setting').content('设置默认').action(setDefault).end()
    .useItem('edit').content('编辑').editRow(editDialog).end()
    .useItem('delete').content('删除').removeRow(removeScriptManagePage, row => [row.ruleId]).end()
    .end()

export default page
